import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const persiste = (store) => {
  store.subscribe((mutaition, state) => {
    const data = JSON.stringify(state)
    window.sessionStorage.setItem("vuexState", data)
  })
}

export default new Vuex.Store({
  plugins: [persiste],
  state: JSON.parse(window.sessionStorage.getItem("vuexState")) || {
    userInfo: { isUp: false },
    what: "",
    timer: "",
    rand: "",
    addrs: "北京市普陀区同普路1435号",
    datas: [],
    oked: [],
    reced: [],
    plugins: [],
    diltes: [],
    Arr: ["0"],
    setTime: {},
    names: ""

  },

  mutations: {
    setUp(state, data) {
      state.userInfo.isUp = data
    },
    setwhat(state, data) {
      state.what = data
    },
    settimer(state, data) {
      state.timer = data
    },
    setrand(state, data) {
      state.rand = data
    },
    setDatas(state, data) {
      state.datas.unshift(data)
    },
    setreced(state, data) {
      state.reced.unshift(data)
    },
    setoked(state, data) {
      state.oked.unshift(data)
    },
    setplugins(state, data) {
      state.plugins.unshift(data)
    },
    setdiltes(state, data) {
      state.diltes.unshift(data)
    },
    setLogin(state, data) {
      state.Arr.push(data)
    },
    setNowDate(state, data) {
      state.setTime = {};
      for (let index = 0; index < state.Arr.length; index++) {
        state.setTime[index] = data;

      }
    },
    setaddrs(state, data) {
      state.addrs = data
    },
    setnames(state, data) {
      state.names = data
    }
  }
})
